package service;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.logging.Logger;
//service层的CURD的异常报错，写入日志
@Component
@Aspect
public class LogAspect {

    private final Logger logger = Logger.getLogger("LogAspect");
    //切点
    @Pointcut("execution(* service.UserService.adduser(..))")
    public void addUserPointCut() {
    }

    @Pointcut("execution(* service.UserService.removeuser(..))")
    public void removeUserPointCut() {
    }

    @Pointcut("execution(* service.UserService.modifyuser(..))")
    public void modifyUserPointCut() {
    }
    //环绕通知
    @Around("addUserPointCut()||removeUserPointCut()||modifyUserPointCut()")
    public boolean aroundAdvice(ProceedingJoinPoint joinPoint) {
        try {
            joinPoint.proceed();//切入点执行
        } catch (Throwable throwable) {
            logger.severe(throwable.toString());
            System.out.println("AOP异常处理...");//todo
            return false;
        }
        return true;
    }
}
